﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
public partial class WebSite_m_show : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null || Session["UserIdentity"].ToString() != "2")
        {
            Response.Redirect("Default.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            return;
        }
        try
        {
            int QuestionId = Convert.ToInt32(Request.QueryString["id"]);
            float a = 0, b = 0, c = 0, d = 0;
            float bili_a = 0, bili_b = 0, bili_c = 0, bili_d = 0;
            QuestionnaireHandler Qhandler = new QuestionnaireHandler();
            DataSet ds = new DataSet();
            ds = Qhandler.GetQuestionnaireResultById(QuestionId);
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (Convert.ToInt32(ds.Tables[0].Rows[i][3]) == 1)
                {
                    a++;
                }
                else if (Convert.ToInt32(ds.Tables[0].Rows[i][3]) == 2)
                {
                    b++;
                }
                else if (Convert.ToInt32(ds.Tables[0].Rows[i][3]) == 3)
                {
                    c++;
                }
                else
                {
                    d++;
                }
            }
            if ((a + b + c + d) != 0)
            {
                bili_a = a / (a + b + c + d);
                bili_b = b / (a + b + c + d);
                bili_c = c / (a + b + c + d);
                bili_d = d / (a + b + c + d);
            }
            DataSet set = new DataSet();
            DataSet Ds = new DataSet();
            QuestionnaireHandler QHandler = new QuestionnaireHandler();
            Ds = QHandler.GetQuestionById(QuestionId);
            string topic = " ", path = " ";
            topic = Ds.Tables[0].Rows[0][1].ToString();
            path = Ds.Tables[0].Rows[0][4].ToString();
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            XmlNodeReader reader = new XmlNodeReader(doc);
            set.ReadXml(reader);
            Session["A"] = bili_a;
            Session["B"] = bili_b;
            Session["C"] = bili_c;
            Session["D"] = bili_d;
            Session["Table"] = set;
        }
        catch(Exception ex)
        {
            //跳转到错误处理页面。
            Session["ErrorMessage"] = ex.Message;
            Session["AtPage"] = "m_show.aspx";
            Response.Redirect("m_error.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            return;
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("m_paper_check.aspx",false);
        return;
    }
}
